<? 
	include('base.php');
	User::protect();
	$section = 'band_gps';
	include_class('band_gps');
	
	$gp = BandGuestPerformer::get($_GET['id']);

	if (!db::isError($gp)) {
		switch ($_GET['task']) {
			case 'update':
				$res = $gp->update($_POST);
				if (!db::isError($res)) {
					header('Location: band_gp_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'deactivate':
				$res = $gp->deactivate();
				if (!db::isError($res)) {
					header('Location: band_gp_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'activate':
				$res = $gp->activate();
				if (!db::isError($res)) {
					header('Location: band_gp_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'delete':
				$res = $gp->remove();
				if (!db::isError($res)) {
					header('Location: band_gps.php');
				}
				break;
		}
	}
	$editors = array('description');
	$page_title = 'Edit Guest Performer';
	include('layout/header.php');
?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_gps.php">Guest Performers&nbsp;&#62;</a>&nbsp;View/Edit Guest Performer
</div>

<? 	if (!db::isError($gp)) {

	if (db::isError($res)) {
		$res->outputList();
	}
	
	$lastname = ($_POST) ? $_POST['lastname'] : $gp->getLastName();
	$firstname = ($_POST) ? $_POST['firstname'] : $gp->getFirstName();
	$function = ($_POST) ? $_POST['function'] : $gp->getFunction();
	$website = ($_POST) ? $_POST['website'] : $gp->getWebsite();
	$description = ($_POST) ? $_POST['description'] : $gp->getDescription();
	
	if (($_GET['task'] == 'edit' || $_GET['task'] == 'update') && User::isAdmin()) { ?>
		
		<h1>edit guest performer:</h1>
		<div class="inset">
		<form id="edit_entry" action="<?=$PHP_SELF?>?task=update&amp;id=<?=$_GET['id']?>" method="post">
		<table border="0" cellspacing="0" cellpadding="0" class="edit-form">
		<tr>
			<td width="50%"><strong>Last Name</strong><br/><input class="text" type="text" name="lastname" value="<?=$lastname?>"></td>
			<td width="50%"><strong>First Name</strong><br/><input class="text" type="text" name="firstname" value="<?=$firstname?>"></td>
		</tr>
		<tr>
			<td><strong>Function</strong><br/><input type="text" class="text" name="function" value="<?=$function?>"></td>
			<td><strong>Website</strong><br/><input type="text" class="text" name="website" value="<?=$website?>"></td>
		</tr>
		</table>
		<div class="edit-form">
		<strong>Description</strong><br/>
		<textarea class="full" name="description" id="description"><?=$description?></textarea>
		</div>
		
		<div class="edit-form">
			<input type="submit" value="Update Performer" name="submit" class="button">
			<input type="submit" value="Exit Without Updating" name="preview" onclick="location.href='<?=$_SERVER['PHP_SELF']?>?id=<?=$gp->getID()?>'; return false" class="button">
		</div>
		</form>
		</div>
		
		
	<? } else { ?>

		<h1>view guest performer:</h1>
		<div class="inset">
		
		<h2><?=$gp->getFirstName()?> <?=$gp->getLastName()?></h2>
		<span class="small">
			Status: <? if ($gp->isActive()) { ?><b>Active</b><? } else { ?><b>Inactive</b><? } ?>
		</span>
		<br><br>
		<? if ($gp->getFunction()) { ?>
			<b>Function:</b><br>
			<?=$gp->getFunction()?><br><br>
		<? } ?>
		<? if ($gp->getDescription()) { ?>
			<b>Description:</b><br>
			<?=$gp->getDescription()?><br><br>
		<? } ?>
		<? if ($gp->getWebsite()) { ?>
			<b>Website:</b><br>
			<a href="<?=$gp->getWebsite()?>" target="_blank"><?=$gp->getWebsite()?></a><br><br>
		<? } ?>
		<form name="entry_status" method="get">
			<? if (User::isAdmin()) { ?>
				<input type="submit" name="" value="Edit Performer" onclick="location.href='<?=$PHP_SELF?>?task=edit&id=<?=$_GET['id']?>';return false" class="button">
				<? if ($gp->isActive()) { ?><input type="submit" name="" value="Deactivate" onclick="location.href='<?=$PHP_SELF?>?task=deactivate&id=<?=$_GET['id']?>';return false" style="margin-right: 5px"><? } else { ?><input type="submit" name="" value="Activate" onclick="location.href='<?=$PHP_SELF?>?task=activate&id=<?=$_GET['id']?>';return false" class="button"><? } ?>
				<input type="submit" value="Remove Performer" name="" onclick="if (confirm('Are you sure you wish to delete this performer?\rDoing so may compromise some release information.\rWhenever possible, deactivate rather than delete.')) { location.href='<?=$PHP_SELF?>?task=delete&id=<?=$_GET['id']?>'};return false" class="button">
			<? } ?>
			<input type="submit" value="Return to Guest Performers" name="" onclick="location.href='band_gps.php'; return false" class="button">
		</form>
		
		</div>
	<? } ?>

<? } else { ?>
	<?=$gp->outputDialog('Return to Guest Performers','band_gps.php')?>
<? } ?>

<? include('layout/footer.php'); ?>
